An iOS Developer’s Guide to SwiftUI by Michele Fadda

An iOS Developer’s Guide to SwiftUI by Michele Fadda

Author:Michele Fadda
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2024-04-02T00:00:00+00:00


Other ways to chop your code

There are many ways besides what I have shown you to structure your apps in Swift, all of which hold significance within SwiftUI. These are other mechanisms that Swift provides to partition a problem into components.

These alternatives haven’t been overlooked, and while we’ll touch upon them briefly, you likely have already come across them.

If any of these concepts are new to you, please revise them as you are likely to meet them. These concepts should be familiar to all Swift developers:

Extensions: Instead of using inheritance, use Swift extensions to add functionality to existing classes, structures, enums, or protocol types. You can also extend types to conform to protocols. This is handy if you need to divide code related to a particular class into separate files or modules.Extensions can be used to group related functionality in separate files so that you avoid having, for example, too-long classes that are unreadable.

In practice, what you define in an extension is still coupled to the entity it refers to but is less coupled in terms of code readability. It is also a better way to add functionality rather than using inheritance.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.